<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数节流</title>
</head>
<body>
<script>
    var throttle = function (fn, interval) {
        var __self = fn,
                timer,
                firstTime = true;
        return function () {
            var args = arguments,
                    __me = this;
            if(firstTime){
                __self.apply(__me,args);
                return firstTime = false;
            }
            if(timer){
                return false;
            }
            timer = setTimeout(function () {
                clearTimeout(timer);
                timer = null;
                __self.apply(__me,args);
            },interval||500);
        };
    };
    window.onresize = throttle(function () {
        console.log(1)
    },500);
</script>
</body>
</html>